package de.koller.worlders.render.util;

import de.koller.worlders.WSea;
import de.koller.worlders.WorldersRoot;
import de.koller.worlders.render.IGLRender;
import org.lwjgl.opengl.GL11;

public class Message extends WSea implements IGLRender {
	
	private boolean show = false;
	private String text = "";

	private SpeechBubble bubble;
	
	@Override
	protected void init() {
		super.init();
		
		bubble = new SpeechBubble( 512 );
		this.addChild( bubble );
		
		wroot.rendering.addGUIElement( this );
	}

	@Override
	protected void release() {
		super.release();
		
		wroot.rendering.removeGUIElement( this );
	}
	
	private void renderTextures() {
		GL11.glColor3f( 1, 1, 1 );	
		bubble.render( new String[] { text }, WorldersRoot.D_WIDTH/2, 250 );
	}

	@Override
	public void renderGL( int elapsedTime ) {
		if( !show )
			return;
		
		renderTextures();
	}

	public boolean isVisible() {
		return show;
	}

	public void show( String text ) {
		this.show = true;
		
		if( !this.text.equals( text ) ) {
			this.text = text;
		}
	}
	
	public void unShow() {
		this.show = false;
	}

}
